package com.ratp.expertisetechnique;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;

import com.ratp.bean.Expertise;
import com.ratp.bean.UtilsBean;
import com.ratp.composants.CustomTextWatcher;

public class SignalementNengageantPasMeca extends Activity {
	private EditText directionMecaPasEditText;
	private EditText freinsMecaPasEditText;
	private EditText boiteVitessMecaPasEditText;
	private EditText transmissionMecaPasEditText;
	private EditText suspensionMecaPasEditText;
	private EditText moteurMecaPasEditText;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.signalement_nengageant_pas_meca);
		
		initVariables();
		initEcouteurs();
	}

	private void initVariables() {
		directionMecaPasEditText = (EditText) findViewById(R.id.editDirectionMecaPas);
		freinsMecaPasEditText = (EditText) findViewById(R.id.editFreinsMecaPas);
		moteurMecaPasEditText = (EditText) findViewById(R.id.editMoteurMecaPas);
		boiteVitessMecaPasEditText = (EditText) findViewById(R.id.editBoiteVitessMecaPas);
		transmissionMecaPasEditText = (EditText) findViewById(R.id.editTransmissionMecaPas);
		suspensionMecaPasEditText = (EditText) findViewById(R.id.editSuspensionMecaPas);

		Expertise expertise = UtilsBean.getExpertiseInstance();
		
		directionMecaPasEditText.setText(expertise.getDirctionNengagePas());
		freinsMecaPasEditText.setText(expertise.getFreinsNengagePas());
		moteurMecaPasEditText.setText(expertise.getMoteurNengagePas());
		boiteVitessMecaPasEditText.setText(expertise.getBoiteVitesseNengagePas());
		transmissionMecaPasEditText.setText(expertise.getTransmissionNengagePas());
		suspensionMecaPasEditText.setText(expertise.getSuspensionNengagePas());
	}

	private void initEcouteurs() {
		directionMecaPasEditText
				.addTextChangedListener(new CustomTextWatcher() {
					@Override
					public void afterTextChanged(Editable s) {
						UtilsBean.getExpertiseInstance().setDirctionNengagePas(
								s.toString());
					}
				});

		freinsMecaPasEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setFreinsNengagePas(
						s.toString());
			}
		});
		moteurMecaPasEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setMoteurNengagePas(
						s.toString());
			}
		});
		boiteVitessMecaPasEditText
				.addTextChangedListener(new CustomTextWatcher() {
					@Override
					public void afterTextChanged(Editable s) {
						UtilsBean.getExpertiseInstance()
								.setBoiteVitesseNengagePas(s.toString());
					}
				});
		transmissionMecaPasEditText
				.addTextChangedListener(new CustomTextWatcher() {
					@Override
					public void afterTextChanged(Editable s) {
						UtilsBean.getExpertiseInstance()
								.setTransmissionNengagePas(s.toString());
					}
				});
		suspensionMecaPasEditText
				.addTextChangedListener(new CustomTextWatcher() {
					@Override
					public void afterTextChanged(Editable s) {
						UtilsBean.getExpertiseInstance()
								.setSuspensionNengagePas(s.toString());
					}
				});
	}
}
